The Practice of Programming Notes
Table of Contents
General
- Official site: http://cm.bell-labs.com/cm/cs/tpop/
- Source code
Chapter 1 Style
page 2
至少,每个名字应该被能显示这个特殊值的作用的所替代。
1.1 Names
- 全局用描述性的名字,本地用短名。
i和j用于循环指数,p和q作指针,s和t作字符串
clarity is often achieved through brevity.
pch 字符指针
- 一致性
- 为函数用主动名字
if (isoctal(c))。。。 使得是或否清晰
- 正确性 : 内容和名字一致性
1.2 Expressions and Statements
- 缩进来显示结构
- 表达式用自然形式
- 用括号解决含糊
- 分解复杂的表达式
- 清晰 the goal is is write clear code, not clever code.
- 小心副作用
i++
有副作用
1.3 Consistency and Idioms
- 使用一致的缩进和括号风格 By the way, if you work on a program you didn't write, preserve the style you find there. When you make a change, don't use your own style even though you prefer it. The program's consistency is more important than your own, because it makes life easier for those who follow.
- 用术语来保持一致性 For an infinite loop, we prefer
for (;;) ... but while (1) ...
is also popular. Don't use anything other than these forms.